package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.dto.role.RoleDTO;
import com.qk.entity.PageResult;
import com.qk.entity.Role;
import com.qk.management.mapper.RoleMapper;
import com.qk.management.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
@SuppressWarnings("all")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;


    @Override
    public PageResult<Role> page(RoleDTO dto) {
        PageHelper.startPage(dto.getPage(), dto.getPageSize());
        List<Role> result =roleMapper.selectByPage(dto);
        Page<Role> rs = (Page<Role>) result;
        return PageResult.<Role>builder()
                .total(Long.valueOf(rs.getTotal()).intValue())
                .rows(rs.getResult())
                .build();
    }

    @Override
    public List<Role> list() {
        return roleMapper.selectAll();
    }
}